local core = require("core")
local exporter = require("plugins.prometheus.exporter")

local plugin_name = "prometheus"

local log = core.log.new(plugin_name..": ")
local schema = {
    type = "object",
    properties = {
        prefer_name = {
            type = "boolean",
            default = false
        }
    },
}


local _M = {
    version = 0.2,
    priority = 500,
    name = plugin_name,
    schema = schema,

    run_policy = "prefer_route",
}

local metrics = {}

function _M.do_in_init_worker()

    exporter.do_in_init()
    --prometheus = base_prometheus.init("prometheus_metrics")
    --metrics.requests = prometheus:counter("nginx_http_requests_total", "Number of HTTP requests", {"host","status","location"})
    ----_M.metric_requests = _M.prometheus:counter("nginx_http_requests_total", "Number of HTTP requests", {"host","status"})
    ----metric.limit_requests = _M.prometheus:counter("nginx_http_limit_requests_total", "Number of Limit HTTP requests", {"host","location"})
    ----metric.limit_request_bytes = _M.prometheus:counter("nginx_http_deny_request_byte", "deny Total size of incoming requests", {"host"})
    --metrics.latency = prometheus:histogram("nginx_http_request_duration_seconds", "HTTP request latency", {"host","location"},{0.005,0.01,0.02,0.03,0.05,0.075,0.1,0.2,0.3,0.4,0.5,0.75,1,2,3,5,10,20,30,60,120,240})
    --metrics.connections = prometheus:gauge("nginx_http_connections", "Number of HTTP connections", {"state"})
    --metrics.response_sizes = prometheus:histogram("nginx_http_response_size_bytes", "Size of HTTP responses", nil, {10,100,1000,10000,100000,1000000})
    --metrics.bytes = prometheus:counter("nginx_http_request_size_bytes", "Total size of incoming requests",{"host"})

end


function _M.do_in_log()
    --log.notice("do_in_log")
    exporter.do_in_log()
    -- body
end




function _M.do_in_access()
    exporter.export_metrics()
end



setmetatable(_M,{
    __tostring = function(self)
        return self.name
    end
})

return _M
